import java.util.LinkedList;
import java.util.Queue;

public class Solution101 {
    public boolean isSymmetric(TreeNode root) {
        if (root == null) {
            return true;
        }
        //return isSymmetric(root.left, root.right);
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root.left);
        queue.offer(root.right);
        while (queue.size() != 0) {
            TreeNode l = queue.poll(), r = queue.poll();
            if (l == null) {
                if (r == null) {
                    continue;
                } else {
                    return false;
                }
            }
            if (r == null) {
                return false;
            }
            if (l.val != r.val) {
                return false;
            }
            queue.offer(l.left);
            queue.offer(r.right);
            queue.offer(l.right);
            queue.offer(r.left);
        }
        return true;
    }
/*
    private boolean isSymmetric(TreeNode left, TreeNode right) {
        if (left == null && right == null) {
            return true;
        }
        if (left == null || right == null) {
            return false;
        }
        if (left.val != right.val) {
            return false;
        }
        return isSymmetric(left.left, right.right) && isSymmetric(left.right, right.left);
    }*/
}
